Skip to content

Conversation

yashranaway
Copy link

Add waitForDatabase polling helper for knowledge bases

Summary

Adds a helper function to poll knowledge base database creation status until the database becomes ONLINE, eliminating the need for manual polling loops.

Changes

  • New waitForDatabase helper function with error handling and configurable options
  • Added method to KnowledgeBases class: client.knowledgeBases.waitForDatabase(kbId)
  • Exported helper types and error classes
  • Includes comprehensive error handling for timeout and failed states
  • Added unit tests

Usage

// Before (manual polling)
while (true) {
   const kb = await client.knowledgeBases.retrieve('123e4567-e89b-12d3-a456-426614174000');
   if (kb.databaseStatus !== "ONLINE") continue;
}

// After (helper function)
const kb = await client.knowledgeBases.waitForDatabase('123e4567-e89b-12d3-a456-426614174000');

Fixes

Closes #5

Add helper function to poll knowledge base database status until ONLINE state.
Includes error handling for failed states, timeout protection, and configurable
polling intervals. Fixes the need for manual polling loops.
@yashranaway
Copy link
Author

@bbatha hey please let me know if you'd like anything changed/updates

Copy link
Collaborator

@bbatha bbatha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great implementation, I'm going to use it as the reference for the others. Thanks for contributing!

import { sleep } from '../../internal/utils/sleep';
import { KnowledgeBaseRetrieveResponse } from './knowledge-bases';

export interface WaitForDatabaseOptions {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add support for AbortSignal?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create a helper function to poll for knowledge base database creation

2 participants